export const DEL_ITEM = 'DEL_ITEM';
export const ADD_ITEM = 'ADD_ITEM';
const listReducer = (state,action) => {

    switch(action.type){
      case "set_loading":{
          return{...state,loading:action.loading}
      }
      case 'set_list':{
          return {...state,list:action.list}
      }
      case 'add_item':{
        const {list} = state
        return {
            ...state,
            list:[...list,{id:list.length,title:action.value}]}
      }
      case 'delete_item':{
        const {list} = state;
        return { 
          ...state, 
          list: list.filter(item => item.id !== action.id)};
      }
      default:{
          return state
      }
    }
  }

export default listReducer